/**
 * Created with JetBrains PhpStorm.
 * User: power_yin
 * Date: 13-9-30
 * Time: 上午10:51
 * To change this template use File | Settings | File Templates.
 */
(function(xf){
    /**
     * @param wrapjQInstance jQuery
     * @param setting = {
     *     slide_count : 每次滚动 多少个，
     *     slidered : 每次滚动文成之后的回调方法
     * }
     */
    xf.VerticalSlider1 = (function( $ ){
        function VerticalSlider1(wrapjQInstance, setting ){
            this.oUl = wrapjQInstance.find('ul');   //获取 ul
            this.aLi = null;
            this.setting = setting;
            this.onceLiHeight = 0;
            this.oUlHeight = 0;
            this._init();
            this.timerId = 0;
        }
        VerticalSlider1.prototype._init = function(){
            this.updateLiNodes();
            this.onceLiHeight = this.aLi.first().height() + (6 * 2);
            this._resumeUlHeight();
        };
        /**
         * 更新 li 节点 集合
         */
        VerticalSlider1.prototype.updateLiNodes = function(){
            this.aLi = this.oUl.find('li.vertical-slider-item'); //获取 所有item li
        };
        VerticalSlider1.prototype._resumeUlHeight = function(){
            this.updateLiNodes();
            this.oUlHeight = this.aLi.length * this.onceLiHeight;
            this.oUl.height( this.oUlHeight );
        };
        /**
         * 开始动画
         */
        VerticalSlider1.prototype.startMoveOnce = function(){
            var that = this;
            this.updateLiNodes();
            this.aLi.each(function(index, li){
                if( index < that.setting.slide_count ){
                    $(li).clone(true).appendTo( that.oUl );
                }
            });
            this._resumeUlHeight();
            this.oUl.stop().animate({ 'top' : '-' + (this.onceLiHeight * this.setting.slide_count) + 'px' }, 1200, 'swing', function(){
                that.updateLiNodes();
                that.aLi.each(function(index, li){
                    if( index < that.setting.slide_count ){
                        $(li).remove();
                    }
                });
                that.oUl.css({ 'top' : '0px' });
                that.setting.slidered(that);    //注册回调
            });
        };
        /**
         * @param time
         */
        VerticalSlider1.prototype.startMoveInterval = function(time){
            var that = this;
            this.timerId = setInterval(function(){
                that.startMoveOnce();
            }, time);
        };
        return VerticalSlider1;
    })(jQuery);

})(XF || ( XF = {} ));
